package com.wfm.leetcode.editor.cn;

import com.wfm.common.TreeNode;

public class POne10平衡二叉树{
//leetcode submit region begin(Prohibit modification and deletion)
class Solution {
    public boolean isBalanced(TreeNode root) {
        if(root==null) return true;
        int d = Math.abs(height(root.left)-height(root.right));
        if(d<=1) {
            return isBalanced(root.left)&&isBalanced(root.right);
        }else return false;
    }
    public int height(TreeNode root){
        if(root==null) return 0;
        return 1+Math.max(height(root.left),height(root.right));
    }

}
//leetcode submit region end(Prohibit modification and deletion)

    public static void main(String[] args) { 
        Solution solution = new POne10平衡二叉树().new Solution();
    }
}